import React from 'react';
import url from "../config/url"
import req from "../http/req"
import { Redirect } from "react-router-dom"
const Checklogin = (Cmp) => {
  return class NewCmp extends React.Component {
    state = {
      isLogin: false,
      isFinish: false
    }
    render() {
      return this.state.isFinish ? this.state.isLogin ? <Cmp {...this.props}/> : <Redirect to="/login"/> : <></>
    }
    componentDidMount() {
      req.get(url.jwt).then((res) => {
        if (res.data.errNo === 0) {
          this.setState({
            isLogin: true,
            isFinish: true
          })
        }else{
          this.setState({
            isLogin: false,
            isFinish: true
          })
        }
      })
    }
  }
}
export default Checklogin;
